package com.singleton.type8;

public class SingletonTest08 {
    public static void main(String[] args) {
        // 测试
        System.out.println("使用枚举");
        Singleton instance = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        System.out.println(instance2 == instance);
        System.out.println("instance.hashCode=" + instance.hashCode());
        System.out.println("instance.hashCode=" + instance2.hashCode());
        instance.sayOK();
    }
}

// 使用枚举，可以实现单例，推荐
enum Singleton {
    INSTANCE; //属性
    public void sayOK() {
        System.out.println("ok~");
    }
}
